package com.yllt4cloud.base.biz.control;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yllt4cloud.base.api.entity.SheBei;
import com.yllt4cloud.base.biz.service.ISheBeiService;
import com.yllt4cloud.common.core.annotation.Inner;
import com.yllt4cloud.common.core.util.ResultResp;
import lombok.AllArgsConstructor;
import org.apache.commons.lang.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @description:
 * @author: yaoxj
 * @create: 2019-12-24 15:26
 **/
@RestController
@AllArgsConstructor
@RequestMapping("/shebei")
public class SheBeiControl {

    ISheBeiService sheBeiService;

    @Inner
    @GetMapping("/getSheBeiById/{sheBeiId}")
    public ResultResp getSheBeiById(@PathVariable String sheBeiId) {
        if(StringUtils.isNotEmpty(sheBeiId)){
            int sheBeiIdQuery = Integer.parseInt(sheBeiId);
            SheBei sheBei=sheBeiService.getById(sheBeiIdQuery);
            if(ObjectUtil.isNotNull(sheBei)){
                return new ResultResp<>(sheBei);
            }
        }
        return null;
    }

    @Inner
    @GetMapping("/getSheBeiByMacAddr/{macAddress}")
    public ResultResp getSheBeiByMacAddr(@PathVariable String macAddress) {
        if(StringUtils.isNotEmpty(macAddress)){
            SheBei sheBei=new SheBei();
            sheBei.setMacAddress(macAddress);
            return new ResultResp(sheBeiService.getOne(new QueryWrapper<>(sheBei)));

        }
        return null;
    }
}
